cmake_minimum_required(VERSION 2.6)

SET(BUILD_SHARED_LIBS ON)
SET(BUILD_DEMOS OFF)

PROJECT ( bullet )
include_directories( dependencies/bullet-2.77 dependencies/bullet-2.77/src )
add_subdirectory( dependencies/bullet-2.77 )

PROJECT(tinyxml)
include_directories(dependencies/tinyxml)
add_subdirectory(dependencies/tinyxml)

PROJECT(glew)
include_directories(dependencies/glew)
add_subdirectory(dependencies/glew)

PROJECT ( bengine )

FIND_PACKAGE ( OpenGL REQUIRED )
IF (OPENGL_FOUND)
  MESSAGE("OPENGL FOUND")
  MESSAGE(${OPENGL_LIBRARIES})
  SET(bengine_LIBS ${bengine_LIBS} ${OPENGL_LIBRARIES}) 
ELSE (OPENGL_FOUND)
  MESSAGE("OPENGL NOT FOUND")
ENDIF (OPENGL_FOUND)

IF (WIN32)
  link_directories( ${CMAKE_SOURCE_DIR}/win32/lib )
  SET(bengine_WIN32LIBS SDLmain.lib SDL.lib SDL_net.lib SDL_image.lib pthreadVSE2.lib libpng.lib freetype.lib) 
  SET(bengine_WIN32INCL ;win32/include;src/utils/ftgl)
  add_definitions(-D__BT_SKIP_UINT64_H -D_USE_MATH_DEFINES -DFTGL_LIBRARY_STATIC -D_CRT_SECURE_NO_WARNINGS -DGLEW_STATIC)
ENDIF (WIN32)

IF (UNIX)
	add_definitions(-DUNIX -DGLEW_STATIC)

	FIND_PACKAGE ( SDL REQUIRED )
	IF (SDL_FOUND)
	MESSAGE("SDL FOUND")
	MESSAGE(${SDL_LIBRARY})
	SET(bengine_LIBS ${bengine_LIBS} ${SDL_LIBRARY}) 
	ELSE (SDL_FOUND)
	MESSAGE("SDL NOT FOUND")
	ENDIF (SDL_FOUND)

	FIND_PACKAGE ( Boost 1.4 COMPONENTS filesystem REQUIRED )
	IF (Boost_FOUND)
	MESSAGE("Boost FOUND")
	MESSAGE(${Boost_FILESYSTEM_LIBRARY})
	SET(bengine_LIBS ${bengine_LIBS} ${Boost_FILESYSTEM_LIBRARY}) 
	ELSE (Boost_FOUND)
	MESSAGE("Boost NOT FOUND")
	ENDIF (Boost_FOUND)

	FIND_PACKAGE ( SDL_image REQUIRED )
	IF (SDLIMAGE_FOUND)
	MESSAGE("SDLIMAGE FOUND")
	MESSAGE(${SDLIMAGE_LIBRARY})
	SET(bengine_LIBS ${bengine_LIBS} ${SDLIMAGE_LIBRARY}) 
	ELSE (SDLIMAGE_FOUND)
	MESSAGE("SDLIMAGE NOT FOUND")
	ENDIF (SDLIMAGE_FOUND)

	FIND_PACKAGE ( SDL_net REQUIRED )
	IF (SDLNET_FOUND)
	MESSAGE("SDLNET FOUND")
	MESSAGE(${SDLNET_LIBRARY})
	SET(bengine_LIBS ${bengine_LIBS} ${SDLNET_LIBRARY}) 
	ELSE (SDLNET_FOUND)
	MESSAGE("SDLNET NOT FOUND")
	ENDIF (SDLNET_FOUND)

	FIND_PACKAGE ( PNG REQUIRED )
	IF (PNG_FOUND)
	MESSAGE("PNG FOUND")
	MESSAGE(${PNG_LIBRARY})
	SET(bengine_LIBS ${bengine_LIBS} ${PNG_LIBRARY}) 
	ELSE (PNG_FOUND)
	MESSAGE("PNG NOT FOUND")
	ENDIF (PNG_FOUND)

	FIND_PACKAGE ( Freetype REQUIRED )
	IF (FREETYPE_FOUND)
	MESSAGE("FREETYPE FOUND")
	MESSAGE(${FREETYPE_LIBRARY})
	SET(bengine_LIBS ${bengine_LIBS} ${FREETYPE_LIBRARY}) 
	SET(bengine_INCLUDES ${bengine_INCLUDES}) 
	ELSE (FREETYPE_FOUND)
	MESSAGE("FREETYPE NOT FOUND")
	ENDIF (FREETYPE_FOUND)
ENDIF (UNIX)

# FIXME
# FIND_PACKAGE ( FTGL )
# IF (FTGL_FOUND)
#   MESSAGE("FTGL FOUND")
#   MESSAGE(${FTGL_LIBRARY})
#   SET(bengine_LIBS ${bengine_LIBS} ${FTGL_LIBRARY}) 
# ELSE (FTGL_FOUND)
#   MESSAGE("FTGL NOT FOUND")
# ENDIF (FTGL_FOUND)

link_libraries (
   ${bengine_LIBS}
)
LINK_DIRECTORIES (
   ${bengine_LIBS_DIRS}
)

SET(bengine_INCLUDES "${CMAKE_SOURCE_DIR};src/utils/bullet;dependencies/bullet;dependencies/tinyxml;${FREETYPE_INCLUDE_DIRS};./${bengine_WIN32INCL}") 
# SET(bengine_INCLUDES "${CMAKE_SOURCE_DIR}/ ./ src/utils/bullet") 
#   MESSAGE(${bengine_INCLUDES})

# CMAKEDEMO_SOURCE_DIR
include_directories( ${bengine_INCLUDES} )

#find_package(KDE4 REQUIRED)

#add_definitions(${QT_DEFINITIONS} ${KDE4_DEFINITIONS})

#include(KDE4Defaults)

#include(MacroLibrary)

#include(ConvenienceLibs.cmake)

#include(ManualStuff.cmake)

#include(ConfigureChecks.cmake)

#include_directories(${KDE4_INCLUDES} ${KDE4_INCLUDE_DIR} ${QT_INCLUDES} )

add_subdirectory(src)


########### install files ###############

# install(FILES  share/critterding/pixmaps/cd.bmp DESTINATION )
# install(FILES  share/critterding/font.ttf DESTINATION )



#original Makefile.am contents follow:

## not a GNU package. You can remove this line, if
## have all needed files, that a GNU package needs
#AUTOMAKE_OPTIONS = foreign 1.4
#
#SUBDIRS = src
#
#pixmapsdir = @datadir@/critterding/pixmaps
#pixmaps_DATA = share/critterding/pixmaps/cd.bmp
#
#fontsdir = @datadir@/critterding/
#fonts_DATA = share/critterding/font.ttf
